package com.bsoft.gol.editor.fileUpload;


import com.bsoft.gol.editor.dao.EditorOrganizationDAO;
import com.bsoft.gol.editor.editor.EditorUser;
import com.bsoft.gol.editor.model.UserInExcel;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;


public class UserValidator implements Validator<UserHolder>{
	private static final Logger logger = LoggerFactory.getLogger(UserValidator.class);
	@Autowired
	EditorOrganizationDAO editorOrganizationDAO;

	@Override
	public boolean validate(TableData<UserHolder> tableData) {
		boolean isValid = true;
		if(tableData.getCount().get() > 0){
			List<UserHolder> list = tableData.getRowData();
			for(UserHolder holder :list ){
				isValid = true;
				if(!validateWmDisease(holder)){
					isValid = false;
					tableData.addInvalidCount();
				}
				holder.setValid(isValid);
			}
		}else{
			isValid = false;
		}
		return isValid;
	}

	
	private boolean validateWmDisease(UserHolder holder){
		EditorUser instance = holder.getEditorUser();
		UserInExcel userInExcel = holder.getUserInExcel();
		boolean isValid = holder.isValid();

        if(StringUtils.isEmpty(userInExcel.getLoginName())){//登录账号
            isValid = false;
            holder.append(ErrorTipConst.SPLIT_CHAR);
            holder.append("登录账号不能为空");
        }

		if(!"0".equals(userInExcel.getUserType())&&!"1".equals(userInExcel.getUserType())){
			isValid = false;
			holder.append(ErrorTipConst.SPLIT_CHAR);
			holder.append("用户类型只能为1或者0");
		}

		if(!"0".equals(userInExcel.getStatus())&&!"1".equals(userInExcel.getStatus())){
			isValid = false;
			holder.append(ErrorTipConst.SPLIT_CHAR);
			holder.append("用户状态只能为0或者1");
		}






		return isValid;
	}
	
}
